Skip to content

Conversation

@dakkar
Copy link

@dakkar dakkar commented Nov 25, 2025

as discussed on p5p: allow sub ($one, \$two, \@three, \%four ||={}) and similar constructrs

Copy link
Contributor

@leonerd leonerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overall this seems fine.

One thing that isn't made super obvious from the doc is the interaction between mutations of referred variables, and defaulting expressions. I suppose you'd get something like a new temporary container that is mutable, but gets thrown away once the call is finished. That's likely how it would fall out of the implementation.

I'd be happy to accept this, but will wait for any comment from @Leont or @ap as well first.

@dakkar
Copy link
Author

dakkar commented Dec 2, 2025

I feel that any clarification on the behaviour of defaulting expressions is outside this PPC, since it's not specific to ref-aliasing.

I agree that the existing documentation does not really explain how:

sub foo($a=[]) { push $a->@*, 1, 2, 3; return $a }

works (it works the way you guessed: each call gets a fresh arrayref)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants